var t = getApp();

Component({
    properties: {
        goodsInfo: {
            type: null
        },
        goodsType: {
            type: null
        },
        popPrice: {
            type: null
        },
        gooddatas: {
            type: null
        },
        start_time: {
            type: null
        },
        end_time: {
            type: null
        },
        isendTime: {
            type: null
        },
        group_price: {
            type: String,
            value: "0"
        }
    },
    observers: {
        goodsInfo: function(t) {
            this.startBuy(t);
        },
        "isendTime,gooddatas,start_time,end_time": function(t, e, i, s) {}
    },
    lifetimes: {
        attached: function(t) {
            var e = new Date().getTime() / 1e3;
            this.setData({
                nowTime: e
            });
            var i = wx.getStorageSync("langIndex");
            this.setData({
                language: i.en
            }), this.data.goodsInfo.has_one_goods_limit_buy && this.data.goodsInfo.has_one_goods_limit_buy.status && this.data.goodsInfo.has_one_goods_limit_buy.display_name && this.setData({
                limitedTimeCustomName: this.data.goodsInfo.has_one_goods_limit_buy.display_name
            });
        }
    },
    data: {
        isBuy: !1,
        isTime: !1,
        isBegTime: !1,
        begTimeStr: "",
        countDownObj: {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00"
        },
        beginTime: 0,
        endTime: 0,
        group_price: "",
        nowTime: "",
        timestamp: Date.parse(new Date()) / 1e3,
        limitedTimeCustomName: "限时购"
    },
    methods: {
        startBuy: function(e) {
            console.log(this.data.goodsType, "36"), "grabGroup" == this.data.goodsType ? t._isTextEmpty(e.start_time) || (this.data.beginTime = this.data.start_time, 
            this.data.endTime = this.data.end_time, this._timeCompare(this.data.beginTime)) : t._isTextEmpty(e.has_one_goods_limit_buy) || (this.setData({
                isBuy: 1 == e.has_one_goods_limit_buy.status
            }), this.triggerEvent("onBuy", {
                isBuy: this.data.isBuy
            }), this.data.beginTime = e.has_one_goods_limit_buy.start_time, this.data.endTime = 1e3 * e.has_one_goods_limit_buy.end_time, 
            this._timeCompare(this.data.beginTime));
        },
        _timeCompare: function(t) {
            var e = new Date(1e3 * parseInt(t));
            new Date() >= e ? (this.setData({
                isTime: !0
            }), this._countDown()) : (this.setData({
                isTime: !1,
                isBegTime: !0,
                begTimeStr: 1e3 * t
            }), this.beginDown());
        },
        _countDown: function() {
            var t = new Date().getTime(), e = this.data.endTime, i = null;
            if (e - t > 0) {
                var s = (e - t) / 1e3, a = parseInt(s / 86400), n = parseInt(s % 86400 / 3600), o = parseInt(s % 86400 % 3600 / 60), m = parseInt(s % 86400 % 3600 % 60);
                i = {
                    day: this._timeFormat(a),
                    hou: this._timeFormat(n),
                    min: this._timeFormat(o),
                    sec: this._timeFormat(m)
                };
            } else i = {
                day: "00",
                hou: "00",
                min: "00",
                sec: "00"
            };
            this.setData({
                countDownObj: i
            }), e - t < 0 ? this.setData({
                countDownObj: {
                    day: "00",
                    hou: "00",
                    min: "00",
                    sec: "00"
                }
            }) : setTimeout(this._countDown.bind(this), 1e3);
        },
        beginDown: function() {
            var t = new Date().getTime(), e = this.data.begTimeStr, i = null;
            if (e - t > 0) {
                var s = (e - t) / 1e3, a = parseInt(s / 86400), n = parseInt(s % 86400 / 3600), o = parseInt(s % 86400 % 3600 / 60), m = parseInt(s % 86400 % 3600 % 60);
                i = {
                    day: this._timeFormat(a),
                    hou: this._timeFormat(n),
                    min: this._timeFormat(o),
                    sec: this._timeFormat(m)
                };
            } else this.setData({
                isTime: !0,
                isBegTime: !1
            }), i = {
                day: "00",
                hou: "00",
                min: "00",
                sec: "00"
            };
            this.setData({
                beginDownObj: i
            }), e - t < 0 ? (this.setData({
                isTime: !0,
                isBegTime: !1
            }), this.setData({
                beginDownObj: {
                    day: "00",
                    hou: "00",
                    min: "00",
                    sec: "00"
                }
            })) : setTimeout(this.beginDown.bind(this), 1e3);
        },
        _timeFormat: function(t) {
            return t < 10 ? "0" + t : t;
        }
    }
});